<?php slot('sub', $sub); ?>
<?php slot('menu', $menu); ?>
<?php slot('user', $user); ?>

<link type="text/css" rel="stylesheet" href="/web/css/agent_page.css" />
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA4ORL54bd4TqneYqWekkc22xhZ1T3gH6A&sensor=false"></script>

<div class="agent_center">
    <div class="agent_page_container">
        <div class="agent_title"><?php echo $agent->getTitle() ?></div>
        <div class="agent_reputation"><?php echo $agent->getReputation() ?></div>
        <div class="agent_description">
            <label>Description</label><div><?php echo $agent->getDescriptionEn() ?></div>
        </div>
        <div class="agent_logo">
            <?php
            if ($agent->getLogo()) {
                $logo = $agent->getLogo();
            } else {
                $logo = '/web/uploads/no_image.png';
            }
            ?>
            <img src="<?php echo $logo ?>">
        </div>
        <div class="agent_country">
            <label>Country</label><div><?php echo $agentCountry->getNameEn() ?></div>
        </div>
        <div class="agent_region">
            <?php if ($agentRegion) {
                $regionName = $agentRegion->getNameEn();
            } else {
                $regionName = '';
            }?>
            <label>Region</label><div><?php echo $regionName ?></div>
        </div>
        <div class="agent_city">
            <?php if ($agentCity) {
                $cityName = $agentCity->getNameEn();
            } else {
                $cityName = '';
            }?>
            <label>City</label><div><?php echo $cityName ?></div>
        </div>
        <div class="agent_address">
            <label title="<?php echo $agent->getAddress() ?>">Address</label><div><?php echo $agent->getAddress() ?></div>
        </div>
        <div class="agent_phone1">
            <label>Phone</label><div><?php echo $agent->getPhone1() ?></div>
        </div>
        <div class="agent_phone2">
            <label>Phone</label><div><?php echo $agent->getPhone2() ?></div>
        </div>
        <div class="agent_fax">
            <label>Fax</label><div><?php echo $agent->getFax() ?></div>
        </div>
        <div class="agent_email">
            <label>E-mail</label><div><?php echo $agent->getEmail() ?></div>
        </div>
        <div class="agent_web_site">
            <label>Web site</label><div><?php echo $agent->getWebsite() ?></div>
        </div>
        <div class="agent_skype">
            <label>Skype</label><div><?php echo $agent->getScype() ?></div>
        </div>
        <div class="agent_working_time">
            <label>Working time</label><div><?php echo $agent->getWorkingTimeFrom() . ' - ' . $agent->getWorkingTimeTo() ?></div>
        </div>
        <div id="agent_map"></div>
        <div class="agent_buttons">
            <?php
            if ($edit) {
                echo '<div class="agent_button_edit"><a href="' . url_for('agentedit', array('agent' => $agent_id)) . '">Edit</a></div>';
            } else {
                echo '<div class="agent_button_edit"><a href="' . url_for('request', array('agent' => $agent_id)) . '">Request to Agent</a></div>';
            }
            ?>

            <div class="agent_button_cancel"><a href="<?php echo url_for($prev) ?>">Cancel</a></div>
        </div>
    </div>

<!--    <div class="agent_page_container">
        <div class="header_agent_block"><span>Comments</span></div>
        <div class="add_new_comment">
            <div class="agent_comment_ratio">
                <label>Rank agent</label>
                <div class="field_stars">
                    <ul>
                        <li value="1"><img src="/web/images/icoStar.png"></li>
                        <li value="2"><img src="/web/images/icoGreyStar.png"></li>
                        <li value="3"><img src="/web/images/icoGreyStar.png"></li>
                        <li value="4"><img src="/web/images/icoGreyStar.png"></li>
                        <li value="5"><img src="/web/images/icoGreyStar.png"></li>
                    </ul>
                </div>
            </div>
            <div class="agent_comment_text">
                <textarea placeholder="Text here..."></textarea>
            </div>
            <div class="agent_comment_send">Send</div>
        </div>
    </div>-->
</div>

<script>
    var save;
    $(function() {
        $('.vaucher_button_print').on('click', function() {
            window.print();
        });

        setTimeout(createHotelMap, 200);

        $('.field_stars ul li').mouseover(function() {
            var c = $(this).val();
            $('.field_stars ul li').each(function(i, v) {
                if (i < c) {
                    $(v).children('img').attr({'src': '/web/images/icoStar.png'});
                } else {
                    $(v).children('img').attr({'src': '/web/images/icoGreyStar.png'});
                }
            });
        }).mouseout(function() {
            var c = $(this).val();
            $('.field_stars ul li').each(function(i, v) {
                if (c !== 1) {
                    if (i > c - 2) {
                        $(v).children('img').attr({'src': '/web/images/icoGreyStar.png'});
                    } else {
                        $(v).children('img').attr({'src': '/web/images/icoStar.png'});
                    }
                }
            });
        });

        $('.field_stars ul').mouseleave(function() {
            $('.field_stars ul li').each(function(i, v) {
                if (i < starsCount) {
                    $(v).children('img').attr({'src': '/web/images/icoStar.png'});
                } else {
                    $(v).children('img').attr({'src': '/web/images/icoGreyStar.png'});
                }
            });
        });

        $('.field_stars ul li').click(function() {
            var clickedStar = $(this).val();

            starsCount = clickedStar;
            $('.field_stars ul li').each(function(i, v) {
                if (i < clickedStar) {
                    if ($(v).attr('selected') === 'selected') {
                        $(v).removeAttr('selected');
                    }
                    $(v).children('img').attr({'src': '/web/images/icoStar.png'});
                } else {
                    if ($(v).attr('selected') === 'selected') {
                        $(v).removeAttr('selected');
                    }
                    $(v).children('img').attr({'src': '/web/images/icoGreyStar.png'});
                }
            });

            $(this).attr({'selected': 'selected'});
        });
    });

    function createHotelMap() {
        var agentLat = '<?php echo $agent->getLatitude() ?>';
        var agentLog = '<?php echo $agent->getLogitude() ?>';
        var position;
        if (agentLat && agentLog) {
            position = [agentLat, agentLog];
        } else {
            position = [29.5513522, 34.9643545];
        }

        var location = new google.maps.LatLng(position[0], position[1]);

        var mapOptions = {
            center: location,
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("agent_map"), mapOptions);

        var marker = new google.maps.Marker({
            position: location,
            map: map
        });
    }

</script>